﻿<%@ WebHandler Language="C#" Class="lists" %>
using Models;
using System;
using System.Web;
using Newtonsoft.Json;
using System.Linq;
using System.Collections.Generic;
using Newtonsoft.Json.Linq;

public class lists : IHttpHandler {

    public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/plain";


        string postdata=Utils.PostInput(context);
        JObject jo = (JObject)JsonConvert.DeserializeObject(postdata);



        string content = jo["content"].ToString();
        string images = jo["images"].ToString();
        string phone=jo["phone"].ToString();

        string latitude=jo["latitude"].ToString();
        string longitude=jo["longitude"].ToString();
        string chooseAddress=jo["chooseAddress"].ToString();



        string authHeader = context.Request.Headers["token"];//Header中的token
        if (string.IsNullOrEmpty(authHeader))
        {
            HttpContext.Current.Response.Write("parameter error");
            return;
        }

        var code = 1;
        var msg = "添加成功";
        var time = DateTime.Now;

        using (Entities bll = new Entities())
        {
            X_help myhelp = new X_help();
            myhelp.HContent = content;
            myhelp.HImges = images;
            myhelp.HGuID = authHeader;

                  myhelp.HTel = phone;

     myhelp.latitude = latitude;
     myhelp.longitude = longitude;
                     myhelp.chooseAddress = chooseAddress;

            myhelp.HGuID = authHeader;


            myhelp.HReTime = DateTime.Now.ToString();
            bll.X_help.Add(myhelp);
            bll.SaveChanges();


            context.Response.Write(JsonConvert.SerializeObject(new { code,msg,time}));

        }
        HttpContext.Current.Response.End();


    }

    public bool IsReusable {
        get {
            return false;
        }
    }




}